﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">

    <ControlTemplate x:Key="ChromeComboBoxControlTemplate" TargetType="{x:Type ComboBox}">
        <Grid SnapsToDevicePixels="True">
            <Grid Grid.IsSharedSizeScope="True">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition SharedSizeGroup="ComboBoxButton" Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Border x:Name="Background" Background="{TemplateBinding Background}"/>
                <Border x:Name="SelectedContentBorder" Margin="2,2,1,2">
                    <ContentPresenter HorizontalAlignment="Left" x:Name="ContentSite" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" Content="{TemplateBinding SelectionBoxItem}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
                </Border>
                <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="2"/>
                <ToggleButton x:Name="DropDownButton" BorderBrush="White" BorderThickness="1" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
                    <ToggleButton.Style>
                        <Style TargetType="{x:Type ToggleButton}">
                            <Setter Property="MinWidth" Value="0"/>
                            <Setter Property="MinHeight" Value="0"/>
                            <Setter Property="Width" Value="Auto"/>
                            <Setter Property="Background" Value="Transparent"/>
                            <Setter Property="Focusable" Value="False"/>
                            <Setter Property="ClickMode" Value="Press"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                                        <Grid Background="Transparent">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition SharedSizeGroup="ComboBoxButton" Width="Auto"/>
                                            </Grid.ColumnDefinitions>
                                            <Border x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="1" SnapsToDevicePixels="True" Width="13">
                                                <Path x:Name="ArrowDownPath" Data="M2.5,0L8.5,0 5.5,3z" Fill="Black" VerticalAlignment="Center"/>
                                            </Border>
                                        </Grid>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsEnabled" Value="False">
                                                <Setter Property="BorderBrush" TargetName="Chrome" Value="{x:Null}"/>
                                            </Trigger>
                                            <MultiTrigger>
                                                <MultiTrigger.Conditions>
                                                    <Condition Property="IsMouseOver" Value="True"/>
                                                    <Condition Property="IsChecked" Value="False"/>
                                                </MultiTrigger.Conditions>
                                                <Setter Property="Background" TargetName="Chrome" Value="#FFC2E0FF"/>
                                            </MultiTrigger>
                                            <Trigger Property="IsChecked" Value="True">
                                                <Setter Property="BorderBrush" TargetName="Chrome" Value="#FF3399FF"/>
                                            </Trigger>
                                            <Trigger Property="IsPressed" Value="True">
                                                <Setter Property="Background" TargetName="Chrome" Value="#FF99CCFF"/>
                                            </Trigger>
                                            <Trigger Property="IsEnabled" Value="False">
                                                <Setter Property="Fill" TargetName="ArrowDownPath" Value="#FFB5B2B5"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ToggleButton.Style>
                </ToggleButton>
                <TextBox x:Name="PART_EditableTextBox" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="1,1,0,1" MinHeight="18" Padding="{TemplateBinding Padding}" Visibility="Collapsed" VerticalAlignment="Center">
                    <TextBox.Style>
                        <Style TargetType="{x:Type TextBox}">
                            <Setter Property="OverridesDefaultStyle" Value="True"/>
                            <Setter Property="AllowDrop" Value="True"/>
                            <Setter Property="MinWidth" Value="0"/>
                            <Setter Property="MinHeight" Value="0"/>
                            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                            <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
                            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type TextBox}">
                                        <ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </TextBox.Style>
                </TextBox>
            </Grid>
            <Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
                <Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}">
                    <Border x:Name="DropDownBorder" BorderBrush="Gray" BorderThickness="1" Background="{TemplateBinding Background}">
                        <ScrollViewer x:Name="DropDownScrollViewer">
                            <Grid RenderOptions.ClearTypeHint="Enabled">
                                <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
                                    <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/>
                                </Canvas>
                                <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained"/>
                            </Grid>
                        </ScrollViewer>
                    </Border>
                </Themes:SystemDropShadowChrome>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                <Setter Property="Background" TargetName="Background" Value="#FFF7F7F7"/>
                <Setter Property="Grid.ColumnSpan" TargetName="Background" Value="2"/>
                <Setter Property="BorderBrush" TargetName="Border" Value="#FFB5B2B5"/>
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsKeyboardFocusWithin" Value="True"/>
                    <Condition Property="IsDropDownOpen" Value="False"/>
                    <Condition Property="IsEditable" Value="False"/>
                </MultiTrigger.Conditions>
                <Setter Property="Background" TargetName="SelectedContentBorder" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
            </MultiTrigger>
            <Trigger Property="IsEditable" Value="True">
                <Setter Property="Background" TargetName="DropDownButton" Value="{x:Null}"/>
                <Setter Property="Visibility" TargetName="ContentSite" Value="Collapsed"/>
                <Setter Property="Visibility" TargetName="PART_EditableTextBox" Value="Visible"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="BorderBrush" TargetName="DropDownButton" Value="#FF3399FF"/>
                <Setter Property="Background" TargetName="DropDownButton" Value="#FFC2E0FF"/>
                <Setter Property="BorderBrush" TargetName="Border" Value="#FF3399FF"/>
            </Trigger>
            <Trigger Property="IsKeyboardFocusWithin" Value="True">
                <Setter Property="BorderBrush" TargetName="DropDownButton" Value="#FF3399FF"/>
                <Setter Property="Background" TargetName="DropDownButton" Value="#FFC2E0FF"/>
                <Setter Property="BorderBrush" TargetName="Border" Value="#FF3399FF"/>
            </Trigger>
            <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
                <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
                <Setter Property="SnapsToDevicePixels" TargetName="Shdw" Value="True"/>
                <Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
            </Trigger>
            <Trigger Property="HasItems" Value="False">
                <Setter Property="MinHeight" TargetName="DropDownBorder" Value="95"/>
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsGrouping" Value="True"/>
                    <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False"/>
                </MultiTrigger.Conditions>
                <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsKeyboardFocusWithin" Value="True"/>
                    <Condition Property="IsDropDownOpen" Value="False"/>
                    <Condition Property="IsEditable" Value="False"/>
                </MultiTrigger.Conditions>
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
            </MultiTrigger>
            <Trigger Property="IsEditable" Value="True">
                <Setter Property="Padding" Value="2"/>
                <Setter Property="IsTabStop" Value="False"/>
            </Trigger>
            <Trigger Property="CanContentScroll" SourceName="DropDownScrollViewer" Value="False">
                <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
                <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

</ResourceDictionary>